package cn.wuxun.sponsor.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.jt.common.pojo.Sponsor;
import com.jt.common.vo.EasyUIResult;

import cn.wuxun.sponsor.mapper.SponsorMapper;
@Service
public class SponsorService {

	@Autowired
	private SponsorMapper sponsorMapper;
	
	/**
	 * 添加赞助商
	 * @param sponsor
	 */
	public void addSponsor(Sponsor sponsor) {
		//补充封装Sponsor sponsor的属性sid,通过UUID随机生成sid
		sponsor.setSid(UUID.randomUUID().toString());
		sponsorMapper.addSponsor(sponsor);
	}

	
	/**
	 * 修改赞助商信息
	 * @param sponsor
	 */
	public void updateSponsor(Sponsor sponsor) {
		
		sponsorMapper.updateSponsor(sponsor);
	}

	/**
	 * 根据sid查询单个赞助商信息
	 * @param sid
	 * @return Sponsor sponsor
	 */
	public Sponsor querySponsorById(String sid) {
		Sponsor sponsor=sponsorMapper.querySponsorById(sid);
		return sponsor;
	}

	/**
	 * 删除赞助商信息
	 * @param sid
	 */
	public void delSponsor(String sid) {
		sponsorMapper.delSponsor(sid);
		
	}

	/**
	 * 分页查询
	 * @param page
	 * @param rows
	 * @return EasyUIResult
	 * 			返回值结构为：Integer total 查询数据总数量
	 * 					  List<?> rows  分页查询的list结果
	 */
	public EasyUIResult querySponsorByPage(Integer page, Integer rows) {
		// 封装数据到EasyUIResult
		//准备一个返回对象，将查询数据set进去然后返回
		EasyUIResult result=new EasyUIResult();
		//第一个属性total的数量
		Integer total=sponsorMapper.queryTotalCount();
		//第二个属性List<product>pList
		Integer start=(page-1)*rows;  //根据页数计算起始位置
		List<Sponsor>sponsorList=sponsorMapper.queryByPage(start,rows);
		//封装数据
		result.setTotal(total);
		result.setRows(sponsorList);
		return result;
	}

	/**
	 * 查询所有赞助商
	 * @return List<Sponsor>sponsorList
	 */
	public List<Sponsor> queryALLSponsor() {
		List<Sponsor>sponsorList=sponsorMapper.queryALLSponsor();
		return sponsorList;
	}

}
